package workspace.test

import Array._

object t2 {
  def main(args: Array[String]): Unit = {
    println("--" * 10)
    var myLst = Array(1, 2, 3, 4, 5);
    for (x <- myLst) {
      println(x)
    }
    println("--" * 10)
    //    计算元素的和
    var total = 0
    for (x <- 0 to (myLst.length - 1)) {
      total += myLst(x);
    }
    println(total)
    println("-*-" * 10)
    // 多维数组
    var myMatrix = Array.ofDim[Int](3, 3)

    for (i <- 0 to 2) {
      for (j <- 0 to 2) {
        myMatrix(i)(j) = j
      }
    }
     // 打印二维阵列
    
    for (i <- 0 to 2) {
      for (j <- 0 to 2) {
        print(" "+myMatrix(i)(j) )
      }
      println()
    }
    println("\n合并数组")
    // 合并数组
    var lst_1=Array(1,2,3,4)
    var lst_2=Array(1,2,3,4)
    var lst_3=Array.concat(lst_1,lst_2)
    for(x <- lst_3){
      println(x)
    }
    println("-*-" * 10)
    // 创建区间数组
    var lst_4=range(1,10)
        for(x <- lst_4){
      println(x)
    }
  }
}